#include<bits/stdc++.h>
#define ll long long
#define pir pair<int,int>
using namespace std;
const int maxn=100005;
int t,n,m,ans,l[maxn],r[maxn];
ll maxl,maxv,p[maxn];

struct node{
    ll d,v,a;
}c[maxn];

ll pw(ll x){return x*x;}

bool cmp(pir x,pir y){
    return x.first<y.first;
}

int main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    cin>>t;
    while(t--){
        cin>>n>>m>>maxl>>maxv,ans=0;
        vector<pir>d;
        for(int i=1,d,v,a;i<=n;i++) cin>>c[i].d>>c[i].v>>c[i].a;
        for(int i=1;i<=m;i++) cin>>p[i],l[i]=r[i]=0;
        l[m+1]=r[m+1]=0;
        for(int i=1,pos,pos_;i<=n;i++){
            if(c[i].a==0){
                if(c[i].v<=maxv) continue;
                pos=lower_bound(p+1,p+m+1,c[i].d)-p,pos_=m;
            }
            else if(c[i].a>0){
                if(lower_bound(p+1,p+m+1,c[i].d)-p>m) continue;
                ll x=(pw(maxv)-pw(c[i].v))/2.0/c[i].a;
                pos=upper_bound(p+1,p+m+1,c[i].d+x)-p,pos_=m;
            }
            else{
                if(c[i].v<=maxv) continue;
                ll x=ceil((pw(maxv)-pw(c[i].v))/2.0/c[i].a);
                pos=lower_bound(p+1,p+m+1,c[i].d)-p,pos_=lower_bound(p+1,p+m+1,c[i].d+x)-p;
                if(pw(maxv)-pw(c[i].v)>=2*c[i].a*(p[pos_]-c[i].d)) pos_--;
            }
            if(pos<=pos_&&pos<=m) ans++,d.push_back(make_pair(pos,pos_)),l[pos]++,r[pos_]++;
        }
        cout<<ans<<" ",ans=0;
        sort(d.begin(),d.end(),cmp);
        vector<int>q;
        for(int i=0;i<d.size();i++) q.push_back(d[i].first),q.push_back(d[i].second);
        sort(q.begin(),q.end());
        for(int i=0,pos=-1,lst=0;i<q.size();i++){
            if(l[q[i]]) pos=q[i];
            if(r[q[i]]&&pos!=-1){
                for(int j=lst;j<d.size();j++){
                    if(d[j].first>pos){lst=j;break;}
                    r[d[j].second]--;
                }
                pos=-1,ans++;
            }
        }
        cout<<m-ans<<"\n";
    }
    return 0;
}